/*
 * INSANE - Interactive Structural Analysis Environment
 *
 * Copyright (C) 2003-2004
 * Universidade Federal de Minas Gerais
 * Escola de Engenharia
 * Departamento de Engenharia de Estruturas
 *
 * Author's email :     insane@dees.ufmg.br
 * Author's Website :   http://www.dees.ufmg.br/insane
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
 * 1307, USA.
 */ 

package br.ufmg.dees.insane.ui.rich.insaneSolver;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Locale;

import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.WindowConstants;
import javax.swing.border.TitledBorder;

import br.ufmg.dees.insane.commons.dialogs.DecimalField;
import br.ufmg.dees.insane.model.femModel.FemModel;


public class SynchronizedSolverSettingsDialog extends JFrame{
	
	/**   */
	private static final long serialVersionUID = 1L;
	
//	Variables declaration - do not modify                     
	private JButton copyButton1;
	private JButton copyButton2;
	private JButton copyButton3;
	private JButton copyButton4;
	private JButton OkButton;
	private JButton cancelButton;
	private JCheckBox meshStateOnOffCheckBox;
	private JCheckBox valueOnOffCheckBox;
	private JCheckBox nodalValuesCheckBox;
	private JCheckBox elementValuesCheckBox;
	private JCheckBox viewOnMeshStateCheckBox;
	private JCheckBox showGraphicCheckBox;
	private JComboBox xAxisValueComboBox;
	private JComboBox yAxisValueComboBox;
	private JComboBox precisionComboBox;
	private JLabel jLabel1;
	private JLabel jLabel10;
	private JLabel jLabel11;
	private JLabel jLabel2;
	private JLabel jLabel3;
	private JLabel jLabel4;
	private JLabel jLabel5;
	private JLabel jLabel6;
	private JLabel jLabel7;
	private JLabel jLabel8;
	private JLabel jLabel9;
	private JList meshStateList;
	private JList valuesList;
	private JPanel meshStatePanel;
	private JPanel scalePanel;
	private JPanel showValuesPanel;
	private JPanel meshLisPanel;
	private JPanel valuesListPanel;
	private JPanel graphicPanel;
	private JScrollPane jScrollPane1;
	private JScrollPane jScrollPane2;
	private JTextField copy1TextField;
	private JTextField copy2TextField;
	private JTextField copy3TextField;
	private DecimalField scaleXTextField;
	private DecimalField scaleYTextField;
	private DecimalField scaleZTextField;
	private JTextField copyValueTextField;
	private JTextField graphicTitleTextField;
	private JTextField sequenceTitleTextField;
	private JTextField nodeTextField;
	private JTextField xAxisTitleTextField;
	private JTextField yAxisTitleTextField;
	// End of variables declaration                   
    private String[] precisionStr = {"0", "0.0", "0.00", "0.000", "0.0000", "0.00000", "0.000000", "0.0000000", "0.00000000"
			 ,"0.000000000","0.0000000000","0.00000000000","0.000000000000"};
	private NumberFormat numberFormat;
	private SolverInterface parent;
	
	/** Creates new form SynchronizedDialog */
	public SynchronizedSolverSettingsDialog(SolverInterface parent) {
		this.parent = parent;
		initComponents();
	}
	public SynchronizedSolverSettingsDialog() {
		initComponents();
	}
	
	/** This method is called from within the constructor to
	 * initialize the form.
	 */
	private void initComponents() {
		
		this.setSize(new Dimension(632,710));
		this.setMaximumSize(new Dimension(632,710));
		this.setMinimumSize(new Dimension(632,710));
		this.setPreferredSize(new Dimension(632,710));
		this.setLocation(150,50);
		this.setResizable(false);
		this.setTitle("Synchronized Settings");
		Image ico = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Insane64.gif"));
		this.setIconImage(ico);
		
		setUpFormat();
		
		meshStatePanel = new JPanel();
		meshStateOnOffCheckBox = new JCheckBox();
		meshLisPanel = new JPanel();
		jScrollPane1 = new JScrollPane();
		meshStateList = new JList();
		copyButton1 = new JButton();
		copyButton2 = new JButton();
		copyButton3 = new JButton();
		copy1TextField = new JTextField();
		copy2TextField = new JTextField();
		copy3TextField = new JTextField();
		scalePanel = new JPanel();
		scaleXTextField = new DecimalField(1,10,numberFormat);
		scaleYTextField = new DecimalField(1,10,numberFormat);
		scaleZTextField = new DecimalField(1,10,numberFormat);
		jLabel1 = new JLabel();
		jLabel2 = new JLabel();
		jLabel3 = new JLabel();
		showValuesPanel = new JPanel();
		valueOnOffCheckBox = new JCheckBox();
		valuesListPanel = new JPanel();
		jScrollPane2 = new JScrollPane();
		valuesList = new JList();
		nodalValuesCheckBox = new JCheckBox();
		elementValuesCheckBox = new JCheckBox();
		copyButton4 = new JButton();
		copyValueTextField = new JTextField();
		viewOnMeshStateCheckBox = new JCheckBox();
		precisionComboBox = new JComboBox();
		jLabel11 = new JLabel();
		graphicPanel = new JPanel();
		showGraphicCheckBox = new JCheckBox();
		xAxisValueComboBox = new JComboBox();
		yAxisValueComboBox = new JComboBox();
		jLabel4 = new JLabel();
		jLabel5 = new JLabel();
		jLabel6 = new JLabel();
		nodeTextField = new JTextField();
		jLabel7 = new JLabel();
		sequenceTitleTextField = new JTextField();
		jLabel8 = new JLabel();
		jLabel9 = new JLabel();
		xAxisTitleTextField = new JTextField();
		yAxisTitleTextField = new JTextField();
		jLabel10 = new JLabel();
		graphicTitleTextField = new JTextField();
		OkButton = new JButton();
		cancelButton = new JButton();
		
		getContentPane().setLayout(null);
		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		
		//setting mesh state panel
		meshStatePanel.setLayout(null);
		meshStatePanel.setBorder(BorderFactory.createTitledBorder(
				null, "Mesh State", TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, new Font("Arial", Font.PLAIN, 12)));
		
		meshStateOnOffCheckBox.setFont(new Font("Arial", Font.PLAIN,12));
		meshStateOnOffCheckBox.setText("Mesh State On/Off");
		meshStateOnOffCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
		meshStateOnOffCheckBox.setMargin(new Insets(0, 0, 0, 0));
		meshStatePanel.add(meshStateOnOffCheckBox);
		meshStateOnOffCheckBox.setBounds(10, 30, 120, 15);
		
		meshLisPanel.setLayout(new GridLayout());
		meshLisPanel.setBorder(BorderFactory.createTitledBorder(""));
		meshStateList.setBackground(new Color(0, 0, 0));
		meshStateList.setForeground(new Color(0, 255, 0));
		meshStateList.setFont(new Font("Arial", Font.PLAIN,12));
		meshStateList.setListData(((FemModel)this.parent.getPersistence().getModel()).getNodeKeys().toArray());
		meshStateList.setFixedCellHeight(20);
		meshStateList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		jScrollPane1.setViewportView(meshStateList);
		
		meshLisPanel.add(jScrollPane1);
		meshStatePanel.add(meshLisPanel);
		meshLisPanel.setBounds(10, 55, 190, 150);
		
		copyButton1.setText(">> Copy >>");
		copyButton1.setFont(new Font("Arial", Font.PLAIN,12));
		meshStatePanel.add(copyButton1);
		copyButton1.setBounds(210, 80, 100, 23);
		copyButton1.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						copy1TextField.setText(addText(meshStateList));
					}
				});
		
		copyButton2.setText(">> Copy >>");
		copyButton2.setFont(new Font("Arial", Font.PLAIN,12));
		meshStatePanel.add(copyButton2);
		copyButton2.setBounds(210, 120, 100, 23);
		copyButton2.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						copy2TextField.setText(addText(meshStateList));
					}
				});
		
		copyButton3.setText(">> Copy >>");
		copyButton3.setFont(new Font("Arial", Font.PLAIN,12));
		meshStatePanel.add(copyButton3);
		copyButton3.setBounds(210, 160, 100, 23);
		copyButton3.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						copy3TextField.setText(addText(meshStateList));
					}
				});
		
		copy1TextField.setBackground(new Color(0, 0, 0));
		copy1TextField.setForeground(new Color(51, 255, 51));
		copy1TextField.setCaretColor(new Color(51, 255, 51));
		copy1TextField.setEditable(false);
		copy1TextField.setFont(new Font("Arial", Font.PLAIN,12));
		copy1TextField.setText("");
		meshStatePanel.add(copy1TextField);
		copy1TextField.setBounds(320, 80, 150, 25);
		
		copy2TextField.setBackground(new java.awt.Color(0, 0, 0));
		copy2TextField.setForeground(new java.awt.Color(51, 255, 51));
		copy2TextField.setFont(new Font("Arial", Font.PLAIN,12));
		copy2TextField.setCaretColor(new Color(51, 255, 51));
		copy2TextField.setEditable(false);
		copy2TextField.setText("");
		meshStatePanel.add(copy2TextField);
		copy2TextField.setBounds(320, 120, 150, 25);
		
		copy3TextField.setBackground(new java.awt.Color(0, 0, 0));
		copy3TextField.setForeground(new java.awt.Color(51, 255, 51));
		copy3TextField.setFont(new Font("Arial", Font.PLAIN,12));
		copy3TextField.setCaretColor(new Color(51, 255, 51));
		copy3TextField.setEditable(false);
		copy3TextField.setText("");
		meshStatePanel.add(copy3TextField);
		copy3TextField.setBounds(320, 160, 150, 25);
		
		//Scale Panel
		scalePanel.setLayout(null);
		scalePanel.setBorder(BorderFactory.createTitledBorder(
				null, "Scale Settings", TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, new Font("Arial", Font.PLAIN, 12)));
		scaleXTextField.setBackground(new Color(0, 0, 0));
		scaleXTextField.setForeground(new Color(51, 255, 51));
		scaleXTextField.setCaretColor(new Color(51, 255, 51));
		scaleXTextField.setText("1");
		scalePanel.add(scaleXTextField);
		scaleXTextField.setBounds(65, 30, 64, 25);
		
		scaleYTextField.setBackground(new Color(0, 0, 0));
		scaleYTextField.setForeground(new Color(51, 255, 51));
		scaleYTextField.setCaretColor(new Color(51, 255, 51));
		scaleYTextField.setText("1");
		scalePanel.add(scaleYTextField);
		scaleYTextField.setBounds(65, 70, 64, 25);
		
		scaleZTextField.setBackground(new Color(0, 0, 0));
		scaleZTextField.setForeground(new Color(51, 255, 51));
		scaleZTextField.setCaretColor(new Color(51, 255, 51));
		scaleZTextField.setText("1");
		scalePanel.add(scaleZTextField);
		scaleZTextField.setBounds(65, 110, 64, 25);
		
		jLabel1.setText("Scale X:");
		jLabel1.setFont(new Font("Arial", Font.PLAIN,12));
		scalePanel.add(jLabel1);
		jLabel1.setBounds(10, 30, 50, 25);
		
		jLabel2.setText("Scale Y:");
		jLabel2.setFont(new Font("Arial", Font.PLAIN,12));
		scalePanel.add(jLabel2);
		jLabel2.setBounds(10, 70, 50, 25);
		
		jLabel3.setText("Scale Z:");
		jLabel3.setFont(new Font("Arial", Font.PLAIN,12));
		scalePanel.add(jLabel3);
		jLabel3.setBounds(10, 110, 50, 25);
		
		meshStatePanel.add(scalePanel);
		scalePanel.setBounds(475, 50, 140, 150);
		
		getContentPane().add(meshStatePanel);
		meshStatePanel.setBounds(0, 10, 625, 220);
		
		//Setting the show value Panel
		showValuesPanel.setLayout(null);
		showValuesPanel.setBorder(BorderFactory.createTitledBorder(
				null, "Value Settings", TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, new Font("Arial", Font.PLAIN, 12)));
		
		valueOnOffCheckBox.setText("Show value On/Off");
		valueOnOffCheckBox.setFont(new Font("Arial", Font.PLAIN,12));
		valueOnOffCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
		valueOnOffCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
		showValuesPanel.add(valueOnOffCheckBox);
		valueOnOffCheckBox.setBounds(10, 30, 120, 15);
		
		valuesListPanel.setLayout(new GridLayout());
		
		valuesListPanel.setBorder(BorderFactory.createTitledBorder(""));
		valuesList.setBackground(new Color(0, 0, 0));
		valuesList.setForeground(new Color(0, 255, 0));
		valuesList.setFont(new Font("Arial", Font.PLAIN,12));
		
		ArrayList<String> elements = ((FemModel)parent.getPersistence().getModel()).getElementKeys();
		ArrayList<String> nodals = ((FemModel)parent.getPersistence().getModel()).getNodeKeys();
		ArrayList<String> keys = new ArrayList<String>();
		keys.addAll(elements);
		keys.addAll(nodals);
		
		valuesList.setListData(keys.toArray());
		valuesList.setFixedCellHeight(20);
		valuesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		jScrollPane2.setViewportView(valuesList);
		
		valuesListPanel.add(jScrollPane2);
		
		showValuesPanel.add(valuesListPanel);
		valuesListPanel.setBounds(10, 60, 190, 140);
		
		nodalValuesCheckBox.setText("Nodal Values");
		nodalValuesCheckBox.setFont(new Font("Arial", Font.PLAIN,12));
		nodalValuesCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
		nodalValuesCheckBox.setMargin(new Insets(0, 0, 0, 0));
		showValuesPanel.add(nodalValuesCheckBox);
		nodalValuesCheckBox.setBounds(220, 70, 120, 23);
		nodalValuesCheckBox.setSelected(true);
		ActionListener nodalValueListenerOnOff = new ChoiceListenerNodalValuesOnOff();  
		nodalValuesCheckBox.addActionListener(nodalValueListenerOnOff);
		
		elementValuesCheckBox.setText("Elements Values");
		elementValuesCheckBox.setFont(new Font("Arial", Font.PLAIN,12));
		elementValuesCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
		elementValuesCheckBox.setMargin(new Insets(0, 0, 0, 0));
		showValuesPanel.add(elementValuesCheckBox);
		elementValuesCheckBox.setBounds(340, 70, 120, 23);
		elementValuesCheckBox.setSelected(false);
		ActionListener elementValueListenerOnOff = new ChoiceListenerElementsOnOff();  
		elementValuesCheckBox.addActionListener(elementValueListenerOnOff);
		
		copyButton4.setText(">> Copy >>");
		copyButton4.setFont(new Font("Arial", Font.PLAIN,12));
		showValuesPanel.add(copyButton4);
		copyButton4.setBounds(220, 115, 100, 23);
		copyButton4.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						copyValueTextField.setText(addText(valuesList));
					}
				});
		
		copyValueTextField.setBackground(new Color(0, 0, 0));
		copyValueTextField.setForeground(new Color(0, 255, 0));
		copyValueTextField.setCaretColor(new Color(0, 255, 0));
		copyValueTextField.setEditable(false);
		copyValueTextField.setText("");
		copyValueTextField.setFont(new Font("Arial", Font.PLAIN,12));
		showValuesPanel.add(copyValueTextField);
		copyValueTextField.setBounds(330, 115, 150, 25);
		
		viewOnMeshStateCheckBox.setText("View on Mesh State");
		viewOnMeshStateCheckBox.setFont(new Font("Arial", Font.PLAIN,12));
		viewOnMeshStateCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
		viewOnMeshStateCheckBox.setMargin(new Insets(0, 0, 0, 0));
		showValuesPanel.add(viewOnMeshStateCheckBox);
		viewOnMeshStateCheckBox.setBounds(220, 165, 135, 23);
		ActionListener viewOnMeshStateListenerOnOff = new ChoiceListenerViewOnMeshStateOnOff();  
		viewOnMeshStateCheckBox.addActionListener(viewOnMeshStateListenerOnOff);
		
		precisionComboBox.setFont(new Font("Arial", Font.PLAIN,12));
		precisionComboBox.setModel(new DefaultComboBoxModel(precisionStr));
		showValuesPanel.add(precisionComboBox);
		precisionComboBox.setSelectedIndex(5);
		precisionComboBox.setBounds(445, 165, 170, 25);
		
		jLabel11.setText("Precision:");
		jLabel11.setFont(new Font("Arial", Font.PLAIN,12));
		showValuesPanel.add(jLabel11);
		jLabel11.setBounds(375, 165, 75, 25);
		
		getContentPane().add(showValuesPanel);
		showValuesPanel.setBounds(0, 230, 625, 220);
		
		
		//Setting Graphic Panel
		graphicPanel.setLayout(null);
		graphicPanel.setBorder(BorderFactory.createTitledBorder(
				null, "Graphic Settings", TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, new Font("Arial", Font.PLAIN, 12)));
		
		showGraphicCheckBox.setText("Show graphic On/Off");
		showGraphicCheckBox.setFont(new Font("Arial", Font.PLAIN,12));
		showGraphicCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
		showGraphicCheckBox.setMargin(new Insets(0, 0, 0, 0));
		graphicPanel.add(showGraphicCheckBox);
		showGraphicCheckBox.setBounds(10, 30, 140, 23);
		
		
//		ArrayList<String> elements = ((FemModel)parent.getPersistence().getModel()).getElementKeys();
//		ArrayList<String> nodals = ((FemModel)parent.getPersistence().getModel()).getNodeKeys();
//		ArrayList<String> keys = new ArrayList<String>();
		keys.add("FinalLoadFactor");
		keys.addAll(nodals);
		keys.addAll(elements);
		
		xAxisValueComboBox.setModel(new DefaultComboBoxModel(keys.toArray()));
		xAxisValueComboBox.setFont(new Font("Arial", Font.PLAIN,12));
		graphicPanel.add(xAxisValueComboBox);
		xAxisValueComboBox.setBounds(90, 100, 180, 25);
		
		yAxisValueComboBox.setModel(new DefaultComboBoxModel(keys.toArray()));
		yAxisValueComboBox.setFont(new Font("Arial", Font.PLAIN,12));
		graphicPanel.add(yAxisValueComboBox);
		yAxisValueComboBox.setBounds(90, 130, 180, 25);
		
		jLabel4.setText("X-axis Value:");
		jLabel4.setFont(new Font("Arial", Font.PLAIN,12));
		graphicPanel.add(jLabel4);
		jLabel4.setBounds(10, 100, 80, 23);
		
		jLabel5.setText("Y-axis Value:");
		jLabel5.setFont(new Font("Arial", Font.PLAIN,12));
		graphicPanel.add(jLabel5);
		jLabel5.setBounds(10, 130, 80, 23);
		
		jLabel6.setText("Node:");
		jLabel6.setFont(new Font("Arial", Font.PLAIN,12));
		graphicPanel.add(jLabel6);
		jLabel6.setBounds(50, 70, 40, 25);
		
		nodeTextField.setBackground(new Color(0, 0, 0));
		nodeTextField.setForeground(new Color(0, 255, 0));
		nodeTextField.setCaretColor(new Color(0, 255, 0));
		nodeTextField.setFont(new Font("Arial", Font.PLAIN,12));
		nodeTextField.setText("");
		graphicPanel.add(nodeTextField);
		nodeTextField.setBounds(90, 70, 64, 25);
		
		jLabel10.setText("Title:");
		jLabel10.setFont(new Font("Arial", Font.PLAIN,12));
		graphicPanel.add(jLabel10);
		jLabel10.setBounds(310, 40, 120, 20);
		
		jLabel7.setText("Sequence Title:");
		jLabel7.setFont(new Font("Arial", Font.PLAIN,12));
		graphicPanel.add(jLabel7);
		jLabel7.setBounds(310, 70, 120, 20);
		
		jLabel8.setText("X-Axis Title:");
		jLabel8.setFont(new Font("Arial", Font.PLAIN,12));
		graphicPanel.add(jLabel8);
		jLabel8.setBounds(310, 100, 120, 20);
		
		jLabel9.setText("Y-Axis Title:");
		jLabel9.setFont(new Font("Arial", Font.PLAIN,12));
		graphicPanel.add(jLabel9);
		jLabel9.setBounds(310, 130, 120, 20);
		
		graphicTitleTextField.setBackground(new Color(0, 0, 0));
		graphicTitleTextField.setForeground(new Color(0, 255, 0));
		graphicTitleTextField.setCaretColor(new Color(0, 255, 0));
		graphicTitleTextField.setText("");
		graphicPanel.add(graphicTitleTextField);
		graphicTitleTextField.setBounds(415, 40, 200, 25);
		
		sequenceTitleTextField.setBackground(new Color(0, 0, 0));
		sequenceTitleTextField.setForeground(new Color(0, 255, 0));
		sequenceTitleTextField.setCaretColor(new Color(0, 255, 0));
		sequenceTitleTextField.setText("");
		sequenceTitleTextField.setFont(new Font("Arial", Font.PLAIN,12));
		graphicPanel.add(sequenceTitleTextField);
		sequenceTitleTextField.setBounds(415, 70, 200, 25);
		
		xAxisTitleTextField.setBackground(new Color(0, 0, 0));
		xAxisTitleTextField.setForeground(new Color(0, 255, 0));
		xAxisTitleTextField.setCaretColor(new Color(0, 255, 0));
		xAxisTitleTextField.setText("");
		xAxisTitleTextField.setFont(new Font("Arial", Font.PLAIN,12));
		graphicPanel.add(xAxisTitleTextField);
		xAxisTitleTextField.setBounds(415, 100, 200, 25);
		
		yAxisTitleTextField.setBackground(new Color(0, 0, 0));
		yAxisTitleTextField.setForeground(new Color(0, 255, 0));
		yAxisTitleTextField.setCaretColor(new Color(0, 255, 0));
		yAxisTitleTextField.setText("");
		graphicPanel.add(yAxisTitleTextField);
		yAxisTitleTextField.setBounds(415, 130, 200, 25);
		
		getContentPane().add(graphicPanel);
		graphicPanel.setBounds(0, 460, 625, 170);
		
		OkButton.setText("OK");
		OkButton.setFont(new Font("Arial", Font.PLAIN,12));
		getContentPane().add(OkButton);
		OkButton.setBounds(227, 640, 80, 25);
		OkButton.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						approvedPerform();
						close(event);
					}
				});
		
		cancelButton.setText("Cancel");
		cancelButton.setFont(new Font("Arial", Font.PLAIN,12));
		getContentPane().add(cancelButton);
		cancelButton.setBounds(318, 640, 80, 25);
		cancelButton.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						close(event);
					}
				});
		
	}// </editor-fold>                        
	
	public String addText(JList list){
		String text="";
		for(int i=0;i<list.getSelectedValues().length;i++){
			text+=((String)list.getSelectedValues()[i]);
		}
		return text;
	}
	
	public void close(ActionEvent event){
		this.dispose();
	}
	
	public void approvedPerform(){
		SynchronizedSettings synchSettings = new SynchronizedSettings();
		if(meshStateOnOffCheckBox.isSelected()){
			synchSettings.setMeshStateOnOff(true);
			synchSettings.setMeshStateKeyX(copy1TextField.getText());
			synchSettings.setMeshStateKeyY(copy2TextField.getText());
			synchSettings.setMeshStateKeyZ(copy3TextField.getText());
			synchSettings.setScaleX(scaleXTextField.getValue());
			synchSettings.setScaleY(scaleYTextField.getValue());
			synchSettings.setScaleZ(scaleZTextField.getValue());
		}else{
			synchSettings.setMeshStateOnOff(false);
		}
		if(valueOnOffCheckBox.isSelected()){
			synchSettings.setValueOnOff(valueOnOffCheckBox.isSelected());
			synchSettings.setNodalValuesOnOff(nodalValuesCheckBox.isSelected());
			synchSettings.setElementsValuesOnOff(elementValuesCheckBox.isSelected());
			synchSettings.setValueKey(copyValueTextField.getText());
			synchSettings.setViewOnMeshStateOnOff(viewOnMeshStateCheckBox.isSelected());
			synchSettings.setPrecision(precisionStr[precisionComboBox.getSelectedIndex()]);
		}else{
			synchSettings.setValueOnOff(false);
		}
		if(showGraphicCheckBox.isSelected()){
			synchSettings.setGraphicOnOff(showGraphicCheckBox.isSelected());
			synchSettings.setNodeLabel(nodeTextField.getText());
			synchSettings.setXAxisValue((String)xAxisValueComboBox.getSelectedItem());
			synchSettings.setYAxisValue((String)yAxisValueComboBox.getSelectedItem());
			synchSettings.setGraphicTitle(graphicTitleTextField.getText());
			synchSettings.setSequenceTitle(sequenceTitleTextField.getText());
			synchSettings.setXAxisTitle(xAxisTitleTextField.getText());
			synchSettings.setYAxisTitle(yAxisTitleTextField.getText());
		}else{
			synchSettings.setGraphicOnOff(false);
		}
		parent.setSynchSettings(synchSettings);
	}
	
	private class ChoiceListenerViewOnMeshStateOnOff implements ActionListener{
		public void actionPerformed(ActionEvent event){
			if(viewOnMeshStateCheckBox.isSelected()){
				if(!meshStateOnOffCheckBox.isSelected()){
					JLabel message = new JLabel();
					message.setFont(new Font("Arial", 0, 12));
					message.setText("You must set Mesh State on and select the respective values!");
					JOptionPane.showMessageDialog(null,message, "Error Message", JOptionPane.WARNING_MESSAGE);
					viewOnMeshStateCheckBox.setSelected(false);
					
				}
			}
				
		}    
	}
	
	private class ChoiceListenerNodalValuesOnOff implements ActionListener{
		public void actionPerformed(ActionEvent event){
			if(nodalValuesCheckBox.isSelected()){
				valuesList.setListData(((FemModel)parent.getPersistence().getModel()).getNodeKeys().toArray());
				nodalValuesCheckBox.setSelected(true);
				elementValuesCheckBox.setSelected(false);
			}else{
				valuesList.setListData(((FemModel)parent.getPersistence().getModel()).getElementKeys().toArray());
				nodalValuesCheckBox.setSelected(false);
				elementValuesCheckBox.setSelected(true);	
			}
		}    
	}
	
	private class ChoiceListenerElementsOnOff implements ActionListener{
		public void actionPerformed(ActionEvent event){
			if(elementValuesCheckBox.isSelected()){
				valuesList.setListData(((FemModel)parent.getPersistence().getModel()).getElementKeys().toArray());
				nodalValuesCheckBox.setSelected(false);
				elementValuesCheckBox.setSelected(true);	
			}else{
				ArrayList<String> elements = ((FemModel)parent.getPersistence().getModel()).getElementKeys();
				ArrayList<String> nodals = ((FemModel)parent.getPersistence().getModel()).getNodeKeys();
				ArrayList<String> keys = new ArrayList<String>();
				keys.addAll(elements);
				keys.addAll(nodals);
				valuesList.setListData(keys.toArray());
				nodalValuesCheckBox.setSelected(true);
				elementValuesCheckBox.setSelected(false);
				
			}
		}    
	}
	
	/**
	 * Sets the number formater
	 */
	private void setUpFormat() {
		numberFormat = (DecimalFormat)NumberFormat.getNumberInstance(Locale.UK);
		numberFormat.setMaximumFractionDigits(5);
	}
	
//	/**
//	 * @param args the command line arguments
//	 */
//	public static void main(String args[]) {
//		java.awt.EventQueue.invokeLater(new Runnable() {
//			public void run() {
//				new SynchronizedSolverSettingsDialog().setVisible(true);
//			}
//		});
//	}
	
	
//*********************************************************************************************	
}//end of this class


